//
//  DecimalCalcModel.m
//  DecimalCalc
//
//  Created by Ediz Turcan on 08.09.11.
//  Copyright 2011 DHBW Stuttgart. All rights reserved.
//

#import "DecimalCalcModel.h"

@implementation DecimalCalcModel

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
        // Testsdasdasadasdas
    }
    
    return self;
}

- (NSString *) decToBin:(NSString *)inputValue {
    int multiplicator = 1;
    int inputV = inputValue.intValue;
    NSString *outputV = @"";
    NSString *oldoutput = @"";
    
    while ((multiplicator*2) <= inputV) {
        multiplicator *= 2;
    }
    while (multiplicator >= 1) {
        oldoutput = outputV;
        if((inputV / multiplicator) >= 1) {
            outputV = [NSString stringWithFormat:@"%@%i", oldoutput, 1];
            inputV -= multiplicator;
        }
        else {
            outputV = [NSString stringWithFormat:@"%@%i", oldoutput, 0];
        }
        multiplicator /= 2;
    }
    return outputV;
}

- (NSString *) calculateNewValue:(methode)methode inputValue:(NSString *)inputValue {
    
    switch (methode) {
        case dec2bin:
            return [self decToBin:inputValue];
            break;
    }
    
}

@end
